import request from './request';

/**
 * 报名培训
 * @param {Object} data - 报名信息
 * @param {number} data.trainingId - 培训ID
 * @returns {Promise}
 */
export function enrollTraining(data) {
  return request({
    url: '/enrollments',
    method: 'post',
    data
  });
}

/**
 * 取消报名
 * @param {number} id - 报名记录ID
 * @returns {Promise}
 */
export function cancelEnrollment(id) {
  return request({
    url: `/enrollments/${id}`,
    method: 'delete'
  });
}

/**
 * 获取我的报名记录
 * @param {Object} params - 查询参数
 * @param {number} params.page - 页码
 * @param {number} params.pageSize - 每页条数
 * @param {number} params.status - 状态
 * @returns {Promise}
 */
export function getMyEnrollments(params) {
  return request({
    url: '/enrollments/mine',
    method: 'get',
    params
  });
}

/**
 * 标记完成
 * @param {number} id - 报名记录ID
 * @returns {Promise}
 */
export function markCompleted(id) {
  return request({
    url: `/enrollments/${id}/complete`,
    method: 'post'
  });
}